﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using INFSWA02.AbstractFactoryModels.Processors;
using INFSWA02.AbstractFactoryModels.Harddisks;
using INFSWA02.BLL.AbstractFactories.AbstractComponentFactory;
using INFSWA02.Models.DecoratorModels;
using INFSWA02.Models.StateModels;
using INFSWA02.Models.OrderStates;
using INFSWA02.BLL.FactoryMethods;

namespace INFSWA02.GUI.Controllers
{
    public class ProductController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult CreateLaptop()
        {
            string product = "macbookpro";
            IProcessor processor = null;
            IHarddisk harddisk = null;
            Laptop laptop = null;

            if (product == "ultrabook")
            {
                IComponentFactory laptopFactory = new MacbookFactory();
                processor = laptopFactory.CreateProcessor();
                harddisk = laptopFactory.CreateHarddisk();
                // laptop = new Ultrabook();
            }
            else if (product == "macbookpro")
            {
                IComponentFactory laptopFactory = new MacbookFactory();
                processor = laptopFactory.CreateProcessor();
                harddisk = laptopFactory.CreateHarddisk();
                
                laptop = new MacBook();
                laptop.processor = processor;
                laptop.harddisk = harddisk;
            }

            laptop = new OneTerrabyteHarddisk(laptop);
            laptop = new OneTerrabyteHarddisk(laptop);

            return View(laptop);
        }

        public ActionResult UpdateMacBook()
        {
            // Decorator
            Laptop macbook = new MacBook();
            macbook = new OneTerrabyteHarddisk(macbook);

            return View(macbook);
        }

        public ActionResult BuyMacBook()
        {
            // Iets doen met de factory method. Static method?
            String laptopParam = "macbook";
            
            LaptopCreator laptopCreator = new ConcreteLaptopCreator();
            Laptop laptop = laptopCreator.CreateLaptop(laptopParam);

            // Abstract Factory
            IComponentFactory laptopFactory = new MacbookFactory();
            IProcessor processor = laptopFactory.CreateProcessor();
            IHarddisk harddisk = laptopFactory.CreateHarddisk();

            laptop.Processor = processor;
            laptop.Harddisk = harddisk;

            // Decorator
            laptop = new OneTerrabyteHarddisk(laptop);

            // State
            Order order = new Order(new OrderNewState());

            order.Id = 1;
            order.Customer = "Wouter Bosland";
            order.Laptop = laptop;
            order.OrderedDate = DateTime.Now;
            
            return View(order);
        }

    }
}
